package main.java.exception.extract;

import main.java.exception.Resource;

import java.util.Stack;

/**
 * @description:    资源池重构
 * <p>
 *     异常不应该成为“条件的替代品”，而应该被用于“异常的”，“罕见的”行为
 * </p>
 * @author:         cong zhi
 * @createDate:     2022/5/31 8:37
 * @updateUser:     cong zhi
 * @updateDate:     2022/5/31 8:37
 * @updateRemark:   修改内容
 * @version:        v1.0
 */
public class ResourcePool {

    private Stack<Resource> available;


    private Stack<Resource> allocated;

    public Resource getResource() {
        Resource result;

        if (available.size() ==0) {
            result = new Resource();
        }else {
            result = available.pop();
        }
        allocated.push(result);
        return result;
    }

}
